import java.io.*;
import java.net.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class SiimuKlient extends Applet implements Runnable, ActionListener{
   TextArea ta=new TextArea();
   TextField tf=new TextField();
   JaagupiRuudustik ruudustik=new JaagupiRuudustik();
   Socket sc;
   PrintWriter pw;
   BufferedReader br;
   
   public static final long serialVersionUID=1;
   public SiimuKlient(){
      setLayout(new BorderLayout());
	  Panel p=new Panel(new GridLayout(2, 1));
	  p.add(ta);
	  p.add(ruudustik);
	  add(p, BorderLayout.CENTER);
	  add(tf, BorderLayout.SOUTH);
	  tf.addActionListener(this);
	  try{
	    sc=new Socket("greeny.cs.tlu.ee", 2525);
		pw=new PrintWriter(sc.getOutputStream(), true);
		br=new BufferedReader(new InputStreamReader(sc.getInputStream()));
	  } catch(Exception e){e.printStackTrace();}
	  new Thread(this).start();
   }
   public void actionPerformed(ActionEvent e){
      if(e.getSource()==tf){
	    pw.println(tf.getText());
		tf.setText("");
	  }
   }
   public void run(){
     try{
	   String rida=br.readLine();
	   while(rida!=null){
	      ta.append(rida+"\n");
		  rida=br.readLine();
	   }
	 } catch(Exception e){e.printStackTrace();}
	 ta.append("ots");
   }
}




